<?php
/**
 * 合约触发管理
 */
namespace app\common\model;

use think\Model;

class TriggerContract extends Model
{
    protected $name = 'trigger_contract';
    public $type = [
        'level kr' =>  '等级KR限制',
        'Mining machine withdrawal' =>  '矿机提现',
        'Dividend withdrawal'   =>  '分红提现'
    ];

    /**
     *  用户合约触发列表
     * @param array $where  条件
     * @param $page 页码
     * @param $limit   分页数量
     * @param string $order 排序
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getList($where = [],$page,$limit,$order = 'id desc'){
        $data = self::where($where)->order($order)->paginate(['list_rows'=>$limit,'page'=>$page])->toArray();
        return $data;
    }

    /**
     * 获取详情
     * @param $id   ID
     * @return TriggerContract|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getDetails($id){
        $data = self::where('id',$id)->find();
        return $data;
    }

    /**
     * 获取最新一条信息
     * @param $mid  用户ID
     * @param $type 类型
     * @return TriggerContract|array|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function newOneInfo($mid,$type){
        $data = self::where('mid',$mid)->where('type',$type)->order('id desc')->find();
        return $data;
    }

}